package com.youlai.boot.modules.webapp.controller;

import com.youlai.boot.common.annotation.Log;
import com.youlai.boot.common.enums.LogModuleEnum;
import com.youlai.boot.common.result.Result;
import com.youlai.boot.core.security.model.AuthenticationToken;
import com.youlai.boot.modules.webapp.common.MyCode;
import com.youlai.boot.shared.auth.service.AuthService;
import io.swagger.v3.oas.annotations.Operation;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/webapp/users")
public class WebAppUserController {
    @Autowired
    private AuthService authService;
    @Operation(summary = "code码")
    @PostMapping("/login")
    @Log(value = "小程序登录", module = LogModuleEnum.LOGIN)
    public Result<AuthenticationToken> login(@RequestBody MyCode myCode) {
        AuthenticationToken authenticationToken = authService.loginByWechat(myCode.getCode());
        return Result.success(authenticationToken);
    }

    // 小程序登出
    @Operation(summary = "小程序登出")
    @DeleteMapping("/logout")
    @Log(value = "小程序登出", module = LogModuleEnum.LOGIN)
    public Result<?> logout() {
        authService.logout();
        return Result.success();
    }
}

